<?php

namespace Api\Model;

use Think\Model;

class MemberModel extends Model {

    protected $tableName = 'classmember';

//group:班主任10，老师3，家长：2;学生：1；
    function addMember($user_id, $class_id, $rname, $power = 0) {
        $data = array(
            'class_id' => $class_id,
            'user_id' => $user_id,
            'rename' => $rname,
            'power' => $power,
            'createtime' => date('Y-m-d H:i;s'),
        );
        $this->add($data);
    }

    function delMember($class_id, $user_id) {
        $where = array('class_id' => $class_id, 'user_id' => $user_id);
    }

    function upMember($user_id, $class_id, $updata) {
        $where = array(
            'user_id' => $user_id,
            'class_id' => $class_id
        );
        $this->where($where)->save($updata);
    }

    function getList($class_id, $start, $limit=30) {
        $limit = $start . ',' . $limit;
        $where = array('class_id' => $class_id);
        return $this->where($where)->limit($limit)->select();
    }

    function getMembyids($user_id, $class_id) {
        $where = array(
            'class_id' => $class_id,
            'user_id' => $user_id
        );
        return $this->where($where)->find();
    }

    function getClassesbyUserid($user_id) {
        $where = array('user_id' => $user_id);
        return $this->where($where)->field('class_id')->limit(5)->select();
    }
    
    function getClasslistbyuid($user_id){
        $where = array('jl_classmember.user_id' => $user_id);
        return $this->join('__CLASS__ on __CLASS__.id=__CLASSMEMBER__.class_id')->where($where)->field('jl_classmember.class_id as classid,jl_class.classname as classname,jl_class.code as code,jl_class.description as description,jl_classmember.power as power')->limit(5)->select();
    }
    
    function getCountbycid($class_id){
        $where=array('class_id'=>$class_id);
        return $this->where($where)->count('id');        
    }

}
